﻿
namespace FastFood.Controls.Complex
{
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using FastFood.Business.Entities.Tipos;
    using FastFood.Business.Logic;

    public partial class BuzonMensajes : UserControl
    {
        public BuzonMensajes()
        {
            InitializeComponent();
        }

        private void BuzonMensajes_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                InitialLoad();
            }
        }

        private void InitialLoad()
        {
            try
            {
                var listaTipoAlertas = new List<string>(Enum.GetNames(typeof(TipoAlerta)));
                listaTipoAlertas.Insert(0, string.Empty);
                this.tscbTipoAlerta.ComboBox.DataSource = listaTipoAlertas;
            }
            catch (Exception) { }
        }

        public void Buscar()
        {
            try
            {
                this.logServicioBindingSource.DataSource = LogServicioManager.Instancia.ListarBySearch(
                    tstbDescripcion.Text.Length == 0 ? null : tstbDescripcion.Text,
                    new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day),
                    tscbTipoAlerta.SelectedIndex == 0 ? (int?)null : tscbTipoAlerta.SelectedIndex,
                    (int)TipoEstadoServicio.Nuevo);
            }
            catch (Exception) { } 
        }

        private void tsbBuscar_Click(object sender, EventArgs e)
        {
            Buscar();
        }

        private void tstbDescripcion_TextChanged(object sender, EventArgs e)
        {
            Buscar();
        }

        private void tscbTipoAlerta_SelectedIndexChanged(object sender, EventArgs e)
        {
            Buscar();
        }
    }
}
